package br.trainee.web.componentes;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;

import br.trainee.web.util.ResponseWrapper;

// Tag-Handler
// BodyTagSupport - classe Tag com corpo
public class TabsTag extends BodyTagSupport{
	
	private String idTabs;
	private String active;
	private String collapsible;
	private String disabled; 
	private String event; 
	private String heightStyle; 
	private String showEffect; 
	private String showDuration; 
	private String hideEffect;
	private String hideDuration; 
	private String create; 
	private String activate; 
	private String beforeActivate; 
	private String beforeLoad; 
	private String load; 
	private String tabsClass;
	private String headerClass;
	
	// É chamado no momento em que a Tag é finalizada
	@Override
	public int doEndTag() throws JspException {
		
		String tab = getBodyContent().getString(); // pegando o corpo do filho
				
		JspWriter saida = pageContext.getOut(); // getOut - retorna o guspidor
		
		HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
		HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
		
		request.setAttribute("tab", tab);
		request.setAttribute("idTabs", idTabs);
		request.setAttribute("active", active);
		request.setAttribute("collapsible", collapsible);
		request.setAttribute("disabled", disabled);
		request.setAttribute("event", event);
		request.setAttribute("heightStyle", heightStyle);
		request.setAttribute("showEffect", showEffect);
		request.setAttribute("showDuration", showDuration);
		request.setAttribute("hideEffect", hideEffect);
		request.setAttribute("hideDuration", hideDuration);
		request.setAttribute("create", create);
		request.setAttribute("activate", activate);
		request.setAttribute("beforeActivate", beforeActivate);
		request.setAttribute("beforeLoad", beforeLoad);
		request.setAttribute("load", load);
		request.setAttribute("tabsClass", tabsClass);
		request.setAttribute("headerClass", headerClass);
		
		// Colocando o response na 'caixa do response' através do construtor
		ResponseWrapper responseWrapper = new ResponseWrapper(response);
		
		RequestDispatcher reqDisp = request.getRequestDispatcher("/resources/componentes-jsp/tabs/tabs.jsp");
		
		try {
			
			reqDisp.include(request, responseWrapper); // Daqui para baixo a interpretação já foi feita, no include, porém é possível ainda utilizar o request e o response
			
			String conteudoComponente = responseWrapper.getString();
			
			// Só gospe conteúdo html, printa a saída
			saida.println(conteudoComponente);
			
		} catch (IOException e) {
			e.printStackTrace();			
		} catch (ServletException e) {
			e.printStackTrace();			
		} 
		
		return super.doEndTag();
	}

	public String getIdTabs() {
		return idTabs;
	}

	public void setIdTabs(String idTabs) {
		this.idTabs = idTabs;
	}

	public String getActive() {
		return active;
	}

	public void setActive(String active) {
		this.active = active;
	}

	public String getCollapsible() {
		return collapsible;
	}

	public void setCollapsible(String collapsible) {
		this.collapsible = collapsible;
	}

	public String getDisabled() {
		return disabled;
	}

	public void setDisabled(String disabled) {
		this.disabled = disabled;
	}

	public String getEvent() {
		return event;
	}

	public void setEvent(String event) {
		this.event = event;
	}

	public String getHeightStyle() {
		return heightStyle;
	}

	public void setHeightStyle(String heightStyle) {
		this.heightStyle = heightStyle;
	}

	public String getShowEffect() {
		return showEffect;
	}

	public void setShowEffect(String showEffect) {
		this.showEffect = showEffect;
	}

	public String getShowDuration() {
		return showDuration;
	}

	public void setShowDuration(String showDuration) {
		this.showDuration = showDuration;
	}

	public String getHideEffect() {
		return hideEffect;
	}

	public void setHideEffect(String hideEffect) {
		this.hideEffect = hideEffect;
	}

	public String getHideDuration() {
		return hideDuration;
	}

	public void setHideDuration(String hideDuration) {
		this.hideDuration = hideDuration;
	}

	public String getCreate() {
		return create;
	}

	public void setCreate(String create) {
		this.create = create;
	}

	public String getActivate() {
		return activate;
	}

	public void setActivate(String activate) {
		this.activate = activate;
	}

	public String getBeforeActivate() {
		return beforeActivate;
	}

	public void setBeforeActivate(String beforeActivate) {
		this.beforeActivate = beforeActivate;
	}

	public String getBeforeLoad() {
		return beforeLoad;
	}

	public void setBeforeLoad(String beforeLoad) {
		this.beforeLoad = beforeLoad;
	}

	public String getLoad() {
		return load;
	}

	public void setLoad(String load) {
		this.load = load;
	}

	public String getTabsClass() {
		return tabsClass;
	}

	public void setTabsClass(String tabsClass) {
		this.tabsClass = tabsClass;
	}

	public String getHeaderClass() {
		return headerClass;
	}

	public void setHeaderClass(String headerClass) {
		this.headerClass = headerClass;
	}


	
}
